package com.alks.function.service.impl.chengKong;

import com.alks.common.data.dto.SysUserTokenDTO;
import com.alks.common.data.thread.UserIdThread;
import com.alks.common.utils.beanutils.BeanUtil;
import com.alks.entity.data.entity.*;
import com.alks.entity.data.enums.ResultCodeEnum;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.chengKong.assort.YfMtlPropertyDetailDto;
import com.alks.function.data.dto.chengKong.assort.YfMtlTypeDetailDto;
import com.alks.function.data.dto.chengKong.assort.YfMtlTypeNewDto;
import com.alks.function.data.request.chengKong.MatterRequest;
import com.alks.function.data.request.chengKong.YfMtlTypeDetailRequest;
import com.alks.function.mapper.chengKong.MaterialManagementMapper;
import com.alks.function.service.chengKong.MaterialManagementService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class MaterialManagementServiceImpl implements MaterialManagementService {

    @Resource
    private MaterialManagementMapper materialManagementMapper;

    /**
     * 分类资料定义列表
     * @return
     */
    @Override
    public List<YfMtlTypeNewDto> getAssortList() {

        //分类资料定义列表
        List<YfMtlTypeNewDto> assortListQuery = materialManagementMapper.getAssortListQuery();

        //获取parentLevel为空的根节点
        List<YfMtlTypeNewDto> list = assortListQuery.stream().filter(parentId -> parentId.getParentLevel() == null).collect(Collectors.toList());

        //根据parentLevel进行分组
        Map<String, List<YfMtlTypeNewDto>> map = assortListQuery.stream()
                .filter(parentId -> StringUtils.isNotBlank(parentId.getParentLevel()))
                .collect(Collectors.groupingBy(YfMtlTypeNewDto::getParentLevel));

        getChildrenModel(list, map);

        //对list进行节点排序
        //包装list
        list = Optional.ofNullable(list)
                //如果集合为空返回空列表替代，避免出现空指针
                .orElseGet(Collections::emptyList)
                .stream()
                //过滤为null元素
                .filter(Objects::nonNull)
                //升序,讲对象的建提取出来
                .sorted(Comparator.comparing(dto -> Integer.parseInt(dto.getOldLevel())))
                .collect(Collectors.toList());

        return list;
    }

    /**
     * 递归遍历节点设置为Children
     * @param list  上一级节点的集合
     * @param map   根据parentId进行分组的map
     */
    private static void getChildrenModel(List<YfMtlTypeNewDto> list, Map<String, List<YfMtlTypeNewDto>> map) {

        //遍历所有根节点
        for (YfMtlTypeNewDto yfMtlTypeNewDto : list) {

            //拿到子节点点
            List<YfMtlTypeNewDto> childList = map.get(yfMtlTypeNewDto.getLevelCode());

            yfMtlTypeNewDto.setChildren(childList);

            if (childList != null && childList.size() > 0) {
                getChildrenModel(childList, map);
            }
        }
    }

    /**
     * 分类资料添加
     * @param mtlTypeNew
     * @return
     */
    @Override
    public ResponseInfo getAssortAdd(YfMtlTypeNew mtlTypeNew) {

        if (mtlTypeNew==null){
            return ResponseInfo.error("请先输入分类编码以及分类名称!");
        }

        //检查参数
        if (StringUtils.isEmpty(mtlTypeNew.getTypeNo())) {
            return ResponseInfo.error(ResultCodeEnum.ASSORT_IS_NULL.getMessage(), ResultCodeEnum.ASSORT_IS_NULL.getCode());
        }

        if (StringUtils.isEmpty(mtlTypeNew.getTypeName())) {
            return ResponseInfo.error("分类名称不能为空!");
        }

        //查询分类代码是否存在
        YfMtlTypeNew yfMtlTypeNew = materialManagementMapper.getByTypeNo(mtlTypeNew.getTypeNo());
        if (yfMtlTypeNew != null) {
            return ResponseInfo.error(ResultCodeEnum.ASSORT_IS_EXIST.getMessage(), ResultCodeEnum.ASSORT_IS_EXIST.getCode());
        }

        mtlTypeNew.setParentLevel(mtlTypeNew.getLevelCode());

        //查询父节点下所有子节点
        List<String> LevelCode = materialManagementMapper.getByLevelCode(mtlTypeNew.getParentLevel());

        //初始化num
        String num = "";
        boolean containsAllNumbers = true;
        for (int i = 1; i <= 99; i++) {

            //生成两位数
            num = String.format("%02d", i);
            //集合中不包含跳出
            if (!LevelCode.contains(mtlTypeNew.getParentLevel() + num)) {
                containsAllNumbers = false;
                break;
            }
        }

        if (containsAllNumbers) {
            // 查询结果中包含1到99，执行相应的操作
            return ResponseInfo.error("目录下已经存在99个目录,已到添加上限!");
        } else {
            mtlTypeNew.setLevelCode(mtlTypeNew.getParentLevel() + num);

            //字符处理
            if (num.startsWith("0")){
                num=num.substring(1);
            }
            mtlTypeNew.setOldLevel(num);
        }

        //添加
        materialManagementMapper.addAssortInfo(mtlTypeNew);

        return ResponseInfo.ok("添加成功!");
    }

    /**
     * 分类资料定义删除
     * @param typeNo
     * @return
     */
    @Override
    public ResponseInfo getAssortDel(String typeNo) {

        //根据主键查询拿到子节点
        YfMtlTypeNew yfMtlTypeNew = materialManagementMapper.getByTypeNo(typeNo);

        //根据子节点查询改节点的父节点
        Integer ParentLevel = materialManagementMapper.getLParentLevel(yfMtlTypeNew.getLevelCode());

        if (ParentLevel > 0) {
            return ResponseInfo.error("该目录存在下级目录分类资料,不允许删除！");
        }

        //查询是否被引用
        List<YfMtlTypeDetail> listCode = materialManagementMapper.getTypeNoCode(typeNo);
        if (!listCode.isEmpty()) {
            return ResponseInfo.error("该分类已经被引用无法删除!");
        }

        materialManagementMapper.delTypeById(typeNo);
        return ResponseInfo.ok("删除成功!");
    }

    /**
     * 分类资料定义单个查询
     * @param typeNo
     * @return
     */
    @Override
    public ResponseInfo getAssortByTypeNo(String typeNo) {
        return ResponseInfo.ok(materialManagementMapper.getByTypeNo(typeNo));
    }

    /**
     * 资料分类定义修改
     * @param yfMtlTypeNew
     * @return
     */
    @Override
    public ResponseInfo getAssortUpdate(YfMtlTypeNew yfMtlTypeNew) {

        List<YfMtlTypeDetail> typeNoCode = materialManagementMapper.getTypeNoCode(yfMtlTypeNew.getTypeNo());
        if (!typeNoCode.isEmpty()) {
            return ResponseInfo.error("该分类已经被引用无法修改!");
        }

        materialManagementMapper.updateByTypeNo(yfMtlTypeNew);
        return ResponseInfo.ok("修改成功!");
    }

    /**
     * 分类资料定义上移
     * @param typeNo
     * @return
     */
    @Override
    @Transactional
    public ResponseInfo getAssortUMoveUp(String typeNo) {

        //获取当前节点的父节点
        YfMtlTypeNew currentNode = materialManagementMapper.getByTypeNo(typeNo);
        if (currentNode != null) {

            //拿到当前节点的所有父节点
            List<YfMtlTypeNewDto> parentLevelList = materialManagementMapper.getParentLevelList(currentNode.getParentLevel());

            //如果不是第一个节点就进行上移操作
            if (parentLevelList != null && !parentLevelList.isEmpty()) {
                //根据当前节点获取节点列表的下标
                int currentIndex = -1;
                for (int i = 0; i < parentLevelList.size(); i++) {
                    YfMtlTypeNewDto node = parentLevelList.get(i);
                    if (node.getTypeNo().equals(typeNo)) {
                        currentIndex = i;
                        break;
                    }
                }

                if (currentIndex == 0) {
                    return ResponseInfo.error("当前目录已经是最上层目录，不能上移!");
                }
                if (currentIndex > 0) {

                    //拿到前一个节点的对象
                    YfMtlTypeNewDto previousNode = parentLevelList.get(currentIndex - 1);

                    //当前节点
                    String currentSort = currentNode.getOldLevel();
                    //前一个节点
                    String prevNodeSort = previousNode.getOldLevel();

                    //交换当前节点与前一个节点
                    currentNode.setOldLevel(prevNodeSort);
                    previousNode.setOldLevel(currentSort);

                    //更新
                    materialManagementMapper.updateLevelCodeByTypeNo(currentNode.getTypeNo(), currentNode.getOldLevel());
                    materialManagementMapper.updateLevelCodeByTypeNo(previousNode.getTypeNo(), previousNode.getOldLevel());

                }
            }
        }

        return ResponseInfo.ok();
    }

    /**
     * 分类资料定义下移
     * @return
     * @param typeNo
     */
    @Override
    @Transactional
    public ResponseInfo getAssortUMoveDown(String typeNo) {
        //获取当前节点的父节点
        YfMtlTypeNew currentNode = materialManagementMapper.getByTypeNo(typeNo);
        if (currentNode != null) {

            //拿到当前节点的所有父节点
            List<YfMtlTypeNewDto> parentLevelList = materialManagementMapper.getParentLevelList(currentNode.getParentLevel());

            //如果不是最后一个节点就下移
            if (parentLevelList != null && !parentLevelList.isEmpty()) {

                //拿到当前节点获取列表的下标
                int currentIndex = -1;
                for (int i = 0; i < parentLevelList.size(); i++) {
                    YfMtlTypeNewDto node = parentLevelList.get(i);
                    if (node.getTypeNo().equals(typeNo)) {
                        currentIndex = i;
                        break;
                    }
                }

                if (currentIndex == parentLevelList.size() - 1) {
                    return ResponseInfo.error("当前目录已经是最底层目录,不能下移！");
                }

                if (currentIndex >= 0 && currentIndex < parentLevelList.size() - 1) {

                    //拿到下一个节点的对象
                    YfMtlTypeNewDto nextNode = parentLevelList.get(currentIndex + 1);

                    //当前节点
                    String currentSort = currentNode.getOldLevel();

                    //下一个节点
                    String nextNodeSort = nextNode.getOldLevel();

                    //交换当前节点与下级节点
                    currentNode.setOldLevel(nextNodeSort);
                    nextNode.setOldLevel(currentSort);

                    //更新
                    materialManagementMapper.updateLevelCodeByTypeNo(currentNode.getTypeNo(), currentNode.getOldLevel());
                    materialManagementMapper.updateLevelCodeByTypeNo(nextNode.getTypeNo(), nextNode.getOldLevel());
                }

            }
        }
        return ResponseInfo.ok();
    }

    /**
     * 材料属性定义列表
     * @return
     */
    @Override
    public ResponseInfo getMaterialPropertiesList() {
        return ResponseInfo.ok(materialManagementMapper.getMaterialPropertiesDetails());
    }

    /**
     * 物料属性定义材料属性定义添加
     * @param yfMtlProperty
     * @return
     */
    @Override
    public ResponseInfo getMaterialPropertiesAdd(YfMtlProperty yfMtlProperty) {

        if (StringUtils.isEmpty(yfMtlProperty.getMtlProperty())) {
            return ResponseInfo.error("请输入材料属性!");
        }

        if (yfMtlProperty.getSeqNo() == null) {
            return ResponseInfo.error("请输入序号!");
        }

        //查询材料属性
        YfMtlProperty mtlProperty = materialManagementMapper.getMtlProperty(yfMtlProperty.getMtlProperty());
        if (mtlProperty != null) {
            return ResponseInfo.error("材料属性已经存在,不能添加!");
        }

        BigDecimal seqNo = materialManagementMapper.getSeqNo(yfMtlProperty.getSeqNo());
        if (seqNo != null) {
            return ResponseInfo.error("该序号已经存在!");
        }

        //拿到用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        yfMtlProperty.setSysUser(userName);
        yfMtlProperty.setSysDate(new Date());

        materialManagementMapper.addMaterialProperties(yfMtlProperty);
        return ResponseInfo.ok("添加成功!");
    }

    /**
     * 物料属性定义材料属性定义删除
     * @param mtlProperty
     * @return
     */
    @Override
    public ResponseInfo getMaterialPropertiesDel(String mtlProperty) {

        //材料属性关联规格表中是否被引用
        List<YfMtlPropertyDetailDto> specList = materialManagementMapper.getMaterialPropertiesSpec(mtlProperty);
        if (!specList.isEmpty()) {
            return ResponseInfo.error("当前属性下还有材料属性规格存在,不能删除！");
        }

        //删除
        materialManagementMapper.delByMtlProperty(mtlProperty);

        return ResponseInfo.ok("删除成功!");
    }

    /**
     * 物料属性定义材料属性关联规格列表
     * @param mtlProperty
     * @return
     */
    @Override
    public ResponseInfo getMaterialPropertiesSpecsList(String mtlProperty) {
        return ResponseInfo.ok(materialManagementMapper.getMaterialPropertiesSpec(mtlProperty));
    }

    /**
     * 物料属性定义材料属性关联规格添加
     * @param yfMtlPropertyDetail
     * @return
     */
    @Override
    public ResponseInfo getMaterialPropertiesSpecAdd(YfMtlPropertyDetail yfMtlPropertyDetail) {

        if (StringUtils.isEmpty(yfMtlPropertyDetail.getMtlProperty())) {
            return ResponseInfo.error("请选择材料属性!");
        }

        if (yfMtlPropertyDetail.getMtlSeq().length() < 4) {
            return ResponseInfo.error("请输入4位数的编号!");
        }

        //根据编号与材料属性查找
        YfMtlPropertyDetail property2MtlSeq = materialManagementMapper.getByMtlProperty2MtlSeq(yfMtlPropertyDetail.getMtlProperty(), yfMtlPropertyDetail.getMtlSeq());
        if (property2MtlSeq != null) {
            return ResponseInfo.error("编号已经存在!");
        }

        if (StringUtils.isEmpty(yfMtlPropertyDetail.getMtlSpec())){
            return ResponseInfo.error("请输入材料规格!");
        }

        //拿到用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        yfMtlPropertyDetail.setSysUser(userName);
        yfMtlPropertyDetail.setSysDate(new Date());

        //添加
        materialManagementMapper.addMaterialPropertiesSpec(yfMtlPropertyDetail);

        return ResponseInfo.ok("添加成功!");
    }

    /**
     * 物料属性定义材料属性关联规格修改
     * @param detail
     * @return
     */
    @Override
    public ResponseInfo getMaterialPropertiesSpecUpdate(YfMtlPropertyDetail detail) {

        //设置用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        detail.setSysUser(userName);
        detail.setSysDate(new Date());
        materialManagementMapper.updateMaterialPropertiesSpec(detail);
        return ResponseInfo.ok("修改成功!");
    }

    /**
     * 物料属性定义材料属性关联规格删除
     * @param mtlProperty
     * @param mtlSpec
     * @return
     */
    @Override
    public ResponseInfo getMaterialPropertiesSpecDel(String mtlProperty, String mtlSpec) {
        if (StringUtils.isEmpty(mtlProperty)&&StringUtils.isEmpty(mtlSpec)){
            return ResponseInfo.error("请求参数错误!");
        }

        materialManagementMapper.delMaterialPropertiesSpec(mtlProperty,mtlSpec);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 物料属性定义宽幅定义列表
     * @return
     */
    @Override
    public ResponseInfo getWideDefinitionList() {
        return ResponseInfo.ok(materialManagementMapper.getWideDefinitionList());
    }

    /**
     * 物料属性定义宽幅定义添加
     * @param yfMtlSpec
     * @return
     */
    @Override
    public ResponseInfo getWideDefinitionAdd(YfMtlSpec yfMtlSpec) {

        if (StringUtils.isEmpty(yfMtlSpec.getMtlSpec())) {
            return ResponseInfo.error("请输入宽幅!");
        }

        //查询宽幅是否存在
        String mtlSpec = materialManagementMapper.getWideDefinitionInfo(yfMtlSpec.getMtlSpec());
        if (!StringUtils.isEmpty(mtlSpec)) {
            return ResponseInfo.error("宽幅已存在!");
        }

        if (yfMtlSpec.getMtlSeq().length() < 4) {
            return ResponseInfo.error("编码需要4位数!");
        }

        //查询编码
        String code = materialManagementMapper.getWideDefinitionCode(yfMtlSpec.getMtlSeq());
        if (!StringUtils.isEmpty(code)) {
            return ResponseInfo.error("编码已经存在!");
        }

        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        yfMtlSpec.setSysUser(userName);
        yfMtlSpec.setSysDate(new Date());

        materialManagementMapper.AddWideDefinition(yfMtlSpec);
        return ResponseInfo.ok("添加成功!");
    }

    /**
     * 宽幅定义修改
     * @param yfMtlSpec
     * @return
     */
    @Override
    public ResponseInfo getWideDefinitionUpdate(YfMtlSpec yfMtlSpec) {

        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();
        yfMtlSpec.setSysUser(userName);
        yfMtlSpec.setSysDate(new Date());

        materialManagementMapper.UpdateWideDefinition(yfMtlSpec);
        return ResponseInfo.ok("修改成功!");
    }

    /**
     * 宽幅定义删除
     * @param mtlUnit
     * @return
     */
    @Override
    public ResponseInfo getWideDefinitionDel(String mtlUnit) {
        materialManagementMapper.delWideDefinition(mtlUnit);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 单位定义列表
     * @return
     */
    @Override
    public ResponseInfo getUnitList() {
        return ResponseInfo.ok(materialManagementMapper.getUnitList());
    }

    /**
     * 单位定义添加
     * @param yfMtlUnit
     * @return
     */
    @Override
    public ResponseInfo getUnitAdd(YfMtlUnit yfMtlUnit) {

        if (yfMtlUnit.getMtlSeq().length() > 2) {
            return ResponseInfo.error("编码长度不能大于2位!");
        }

        //查询单位编码
        String unitCode = materialManagementMapper.getUnitCode(yfMtlUnit.getMtlSeq());
        if (!StringUtils.isEmpty(unitCode)) {
            return ResponseInfo.error("编码已经存在!");
        }

        //查询中文单位
        String chineseUnit = materialManagementMapper.getChineseUnit(yfMtlUnit.getMtlUnit());
        if (!StringUtils.isEmpty(chineseUnit)) {
            return ResponseInfo.error("单位已存在!");
        }

        //获取用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        yfMtlUnit.setSysUser(userName);
        yfMtlUnit.setSysDate(new Date());

        //添加
        materialManagementMapper.addUnit(yfMtlUnit);
        return ResponseInfo.ok("添加成功");
    }

    /**
     * 单位定义修改
     * @param yfMtlUnit
     * @return
     */
    @Override
    public ResponseInfo updateUnit(YfMtlUnit yfMtlUnit) {

        //获取用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        yfMtlUnit.setSysUser(userName);
        yfMtlUnit.setSysDate(new Date());
        materialManagementMapper.updateUnit(yfMtlUnit);
        return ResponseInfo.ok("修改成功!");
    }

    /**
     * 单位定义删除
     * @param mtlUnit
     * @return
     */
    @Override
    public ResponseInfo getUnitDel(String mtlUnit) {

        materialManagementMapper.delUnit(mtlUnit);
        return ResponseInfo.ok("删除成功!");
    }

    /**
     * 贴合加工方式定义列表
     * @return
     */
    @Override
    public ResponseInfo getFitList() {
        return ResponseInfo.ok(materialManagementMapper.getFitList());
    }

    /**
     * 贴合加工方式定义添加
     * @return
     */
    @Override
    public ResponseInfo getFitAdd(YfMtlPrdType yfMtlPrdType) {

        if (yfMtlPrdType.getSeqNo() == null) {
            return ResponseInfo.error("请输入序号!");
        }

        String fitNo = materialManagementMapper.getFitNo(yfMtlPrdType.getSeqNo());
        if (!StringUtils.isEmpty(fitNo)){
            return ResponseInfo.error("序号已经存在!");
        }

        String fitType = materialManagementMapper.getFitType(yfMtlPrdType.getPrdType());
        if (!StringUtils.isEmpty(fitType)) {
            return ResponseInfo.error("加工方式已存在!");
        }

        //获取用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();
        yfMtlPrdType.setSysUser(userName);
        yfMtlPrdType.setSysDate(new Date());
        materialManagementMapper.addFit(yfMtlPrdType);
        return ResponseInfo.ok("添加成功!");
    }

    /**
     * 贴合加工方式修改
     * @param yfMtlPrdType
     * @return
     */
    @Override
    public ResponseInfo getFitUpdate(YfMtlPrdType yfMtlPrdType) {
        //获取用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        yfMtlPrdType.setSysUser(userName);
        yfMtlPrdType.setSysDate(new Date());
        materialManagementMapper.updateFit(yfMtlPrdType);
        return ResponseInfo.ok("修改成功!");
    }

    /**
     * 贴合加工方式删除
     * @param prdType
     * @return
     */
    @Override
    public ResponseInfo getFitDel(String prdType) {
        materialManagementMapper.delFit(prdType);
        return ResponseInfo.ok("删除成功!");
    }

    /**
     * 分类建档列表
     * @param request
     * @return
     */
    @Override
    public ResponseInfo getTypeDetail(MatterRequest request) {

        List<YfMtlTypeDetailDto> typeDetailList = materialManagementMapper.getTypeDetailList(request);
        return ResponseInfo.ok(typeDetailList);
    }

    /**
     * 分类建档添加
     * @param yfMtlTypeDetail
     * @return
     */
    @Override
    public ResponseInfo getTypeDetailAdd(YfMtlTypeDetail yfMtlTypeDetail) {

        YfMtlProperty mtlProperty = materialManagementMapper.getMtlProperty(yfMtlTypeDetail.getMtlProperty());
        if (mtlProperty == null) {
            return ResponseInfo.error("材料属性不存在,请先定义!");
        }

        String mtlProperty2 = materialManagementMapper.getYfMtlTypeDetail(yfMtlTypeDetail);
        if (!StringUtils.isEmpty(mtlProperty2)){
            return ResponseInfo.error("该材料属性已存在!");
        }

        //获取用户名
        SysUserTokenDTO dto  = UserIdThread.get();
        String userName = dto.getUserName();

        yfMtlTypeDetail.setSysUser(userName);
        yfMtlTypeDetail.setSysDate(new Date());

        materialManagementMapper.addTypeDetail(yfMtlTypeDetail);
        return ResponseInfo.ok("添加成功!");
    }

    /**
     *分类建档修改
     * @param request
     * @return
     */
    @Override
    public ResponseInfo getTypeDetailUpdate(Map<String, YfMtlTypeDetailRequest> request) {

        if (request.size()!=2){
            return ResponseInfo.error("请求参数错误!");
        }

        //获取key
        YfMtlTypeDetailRequest updateTop = request.get("updateTop");
        YfMtlTypeDetailRequest updateEnd = request.get("updateEnd");

        YfMtlProperty mtlProperty = materialManagementMapper.getMtlProperty(updateEnd.getMtlProperty());
        if (mtlProperty==null){
            return ResponseInfo.error("材料属性不存在,请先定义!");
        }

        if (updateTop.isEquals(updateEnd)){
            return ResponseInfo.error("新材料属性与原材料属性一样,不能修改!");
        }

        YfMtlTypeDetail yfMtlTypeDetail = new YfMtlTypeDetail();
        BeanUtil.copyProperties(updateEnd,yfMtlTypeDetail);
        SysUserTokenDTO dto = UserIdThread.get();
        String userName = dto.getUserName();
        yfMtlTypeDetail.setSysUser(userName);
        yfMtlTypeDetail.setSysDate(new Date());

        materialManagementMapper.updateTypeDetail(yfMtlTypeDetail,updateTop);

        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 分类建档删除
     * @param request
     * @return
     */
    @Override
    public ResponseInfo getTypeDetailDel(YfMtlTypeDetailRequest request) {

        if (request==null){
            return ResponseInfo.error("请求参数错误!");
        }

        materialManagementMapper.delTypeDetailDel(request);
        return ResponseInfo.ok("操作成功!");
    }
}
